package clustering;
import java.util.*;

import org.apache.commons.math3.stat.descriptive.DescriptiveStatistics;
public class Thresholds {
	private Map<String,List<Double>> thresholds;
	public void Get_Clusters_Similarity(List<Integer> cluster_size, ArrayList<ArrayList<Ngram_Profile>>clusters_profile){
		thresholds = new HashMap<String,List<Double>>();
		for(int i=0; i<clusters_profile.size(); i++)
			for(int j=i+1; j<clusters_profile.size(); j++){
				double cosine = new Cluster_Similarity_by_GlobalProfile().CosineSimilarity_between_Clusters(clusters_profile.get(i),clusters_profile.get(j));
				int size1 = cluster_size.get(i);
				int size2 = cluster_size.get(j);
				String key = String.valueOf(size1)+"\t"+String.valueOf(size2);
				if(size1 > size2)
					key = String.valueOf(size2)+"\t"+String.valueOf(size1);
				if(thresholds.containsKey(key))
					thresholds.get(key).add(cosine);
				else{
					List<Double> values = new ArrayList<Double>();
					values.add(cosine);
					thresholds.put(key, values);
				}
			}
	}
	
	public HashMap<String,Double> GetThresholds(){
		Set keyset = thresholds.keySet();
		List<String> keys = new ArrayList(keyset);
		HashMap<String,Double> final_thresholds = new HashMap<String,Double>();
		for(String key: keys){
			DescriptiveStatistics stats = new DescriptiveStatistics();
			List<Double> values = thresholds.get(key);
			for(double value: values)
				stats.addValue(value);
			double mean = stats.getMean();
			double dev = stats.getStandardDeviation();
			double t = mean + 3*dev;
			final_thresholds.put(key, t);
		}
		return final_thresholds;
	}
}
